/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import AdminOperations.AdminManageMembers;
import MemberOperation.MemberThreadOperation;
import java.io.PrintWriter;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import xmlMapping.Member;
import xmlMapping.Thread;
import xmlMapping.Post;

/**
 *
 * @author ABDELMOHSEN
 */
public class GetStats extends org.apache.struts.action.Action {
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        PrintWriter out=response.getWriter();
        Iterator<Member> members=new AdminManageMembers().searchMembers(request.getParameter("u"));
        Member m=null;
        Iterator<Post> mPosts=null;
        int rank=0;
        out.println("<table id='header' align='center' width='1200'><tr><td><h3>Username</h3></td><td><h3>Email</h3></td><td><h3>Type</h3></td><td><h3>Nomber of Posts</h3></td><td><h3>Nomber of Threads</h3></td><td><h3>Total Post Rank</h3></td></tr>");
        while(members.hasNext()){
            m=members.next();        
            out.print("<tr><td>");
            out.print(m.getUserName());
            out.print("</td><td>");
            out.print(m.getEmail());
            out.print("</td><td>");
            out.print(m.getType());
            out.print("</td><td>");
            out.print(m.getPosts_1().size());
            out.print("</td><td>");
            out.print(m.getThreads_1().size());
            out.print("</td><td>");
            mPosts=m.getPosts_1().iterator();
            while(mPosts.hasNext()) rank+=(mPosts.next()).getRank();
            out.print(rank);
            out.print("</td></tr>");
        }
        out.println("</table>");
        return mapping.findForward(null);
    }
}
